
class Animal{      //父类
    public String  name;
    public int   age;
    //父类的构造方法
    //------------------------
    public  Animal(String name,int age){
        this.name = name;
        this.age = age;
    }

    public void local(){

        System.out.println(this.name+"在门口");
    }
    public void eat(){
        System.out.println(this.name+"正在吃东西");
    }
}

class Dog extends Animal{    //子类
    public  Dog(String name,int age){
        super(name,age);
    }
    public void bark(){

        System.out.println(this.name+"狗叫");
    }
    public void eat(){
        System.out.println(this.name+"吃狗粮");
    }
}

class Cat extends Animal{
    //子类的构造方法  的构造，需要在构造方法中初始化
    public  Cat(String name,int age){
//调用父类的构造方法，初始化从父类继承的成员对象，并不会生成父类对象
        super(name,age) ;
    }
    public void sleep(){
        System.out.println(this.name+"睡觉");

    }
}

public class Test {
    /*public static Animal fun(){
        Dog dog = new Dog("老二",12);
        return dog;


    }*/
    public static void main(String[] args) {

       // Animal animal=fun();



        /*Dog dog = new Dog("老二",12);
        Animal animal=dog;*/
        //将子类对象给父类
        Animal animal=new Dog("老二",12);
        if(animal instanceof Cat){
            Cat cat=(Cat) animal;

        }else{
            System.out.println("类型不匹配");
        }

        Dog dog=(Dog) animal;
        animal.eat();  //调用父类的


        //  调用构造方法，  对子类进行实例化对象





        Cat cat = new Cat("老二",12);
        cat.sleep();
    }







}
